package com.cms.manage.util;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Map;

import org.springframework.web.multipart.MultipartFile;

import com.alibaba.druid.sql.visitor.functions.Concat;
import com.cms.manage.common.ConmonConfig;

public class UploadBaseFileUtil {
	
	
	/**上传图片到服务器
	 * 不存在创建新的文件
	 * logFileName文件名
	 * content 文件内容
	 * path 文件相对路径
	 * type 后缀名
	 * @throws  
	 * @throws IOException 
	 * */
	public static String  writeFileByData(String fileName,MultipartFile  inputfile,String path) throws IOException{
		File file =new File(System.getProperty("user.dir"));  
		//获取服务器根目录
		Boolean flag = true;
		while(flag){
			if(file.getParentFile()==null){
				flag=false;
			}else{
				file=file.getParentFile();
			}
		}
		String basePath = file.getPath()+path;
		file =new File(basePath); 
		//判断文件目录是否存在否则创建
		if(!file.exists()){
			file.mkdirs();	
		}
        String fileUpName=fileName;
        File saveFile = new File(file, fileUpName);
        inputfile.transferTo(saveFile);           
        return ConmonConfig.getHostIP()+ Constant.BACK_IMG_LOOK +fileName;
       
	}
	/**
	 *上传图片
	 * 
	 * */
	  public static void uploadImg(Map<String, String> data,MultipartFile file){
		  /*String path = System.getProperty("file.separator")+"usr"+System.getProperty("file.separator")+"share"
				         +System.getProperty("file.separator")+"nginx"+System.getProperty("file.separator")+"html"
				         +System.getProperty("file.separator")+"backimg";*/
		  String path = data.get("path");//上传文件地址
		  String type = data.get("type");//文件类型
		  String fileName=data.get("fileName");//文件名		
		 // UploadBaseFileUtil.writeFileByData(fileName,file,path,type); 
	  }	
   public static void main(String[] args) {

	   System.out.println(DateTimeUtil.getDateYMDHMS(new Date()));
	 //  UploadBaseFileUtil.writeLogByText(DateTimeUtil.getDateYM(new Date())+"_"+"ceshi"+"_"+"ceshi12", "1", System.getProperty("file.separator")+"logss"+System.getProperty("file.separator")+"iosverify","txt");
	   
}
}
